<?php

class App_Model_DbTable_Shopping extends Ext_Db_Table  
{  
    protected $_name = 'shopping';
    
    public function getRowById($id)
    {
        if(!$id)
        {
            return "";
        }
        
        $db = $this->getAdapter();
        $safe = $db->quoteInto(" id = ? ", $id);
        $row = $this->fetchRow($safe);
        if (!$row) {
            //throw new Exception("Count not find row $id");
            return "";
        }
        return $row->toArray();
    }
    
    public function getRowByHostViewId($host, $viewId)
    {
        if(!$host || !$viewId)
        {
            return "";
        }

        $row = $this->fetchRow(" host = '$host' AND viewId = '$viewId' ");
        
        if (!$row) {
            //throw new Exception("Count not find row $id");
            return "";
        }
        return $row->toArray();
    }
    
    public function addNew($inputArray)
    {
        $row = array (
            'host'               => $inputArray['host'],
            'viewId'             => $inputArray['viewId'],
            'url'                => $inputArray['url'],
            'imageId'            => $inputArray['imageId'],
            'price'              => $inputArray['price'],
            'createTime'         => $inputArray['createTime'],
        );
        try {
            $rows_affected = $this->insert($row);
            $last_insert_id = $this->getAdapter()->lastInsertId();
        }catch (Exception $e){
            trigger_error($e->getMessage(), E_USER_WARNING);
        }
        return $last_insert_id;
    }
}  

